#!/bin/bash 
set -e


TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage4}
SRC=${SRC:-/sources}

name=js78
version=78.7.1

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/firefox-${version}esr.source.tar.xz -C $TMP

{ time \
   {

    cd $TMP/firefox--$version
    
	mountpoint -q /dev/shm || mount -t tmpfs devshm /dev/shm

	export SHELL=/bin/sh

	mkdir obj
	cd    obj

	CC=gcc CXX=g++ \
	../js/src/configure --prefix=/usr            \
	                    --with-intl-api          \
	                    --with-system-zlib       \
	                    --with-system-icu        \
	                    --disable-jemalloc       \
	                    --disable-debug-symbols  \
	                    --enable-readline
	make

	make install
	rm -v /usr/lib/libjs_static.ajs
	sed -i '/@NSPR_CFLAGS@/d' /usr/bin/js78-config

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
